package com.hexiang.client.handler;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.hexiang.domain.CommonResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

@Slf4j
public class UserHttpApiClientBlockHandler {

    public static CommonResponse<Serializable> catchBlock(BlockException ex) {
        if (ex instanceof FlowException) {
            return CommonResponse.fail(-23, "服务执行发生限流");
        } else {
            return CommonResponse.fail(-22, "服务执行发生降级");
        }
    }

    public static CommonResponse<Serializable> getUsers(BlockException ex) {
        log.error("getUsersErr", ex);
        return catchBlock(ex);
    }

    public static CommonResponse<Serializable> errTest(BlockException ex) {
        log.error("errTestErr", ex);
        return catchBlock(ex);
    }
}